package org.example.onetry.fileter;



import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.logging.LogRecord;
//哪些路径会经过该filter '/*'代表全路径
@WebFilter (urlPatterns = {"/*"})
public class filte implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {


    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        //这部分该过滤器必须执行的代码
        System.out.println("filte");
        //当经过过滤器时，请求和响应都会被拦截在此处，必须使用过滤器链进行放行

        response.setContentType("text/html");
        request.setCharacterEncoding("UTF-8");
        filterChain.doFilter(request,response);
    }

    @Override
    public void destroy() {
        System.out.println("destroy");
    }
}
